home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / amiga / sipp.lha / sipp / demo / chain.c next >
C/C++ Source or Header  |  1993-03-13  |  3KB  |  115 lines

  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. #include <sipp.h>
  5. #include <primitives.h>
  6.  
  7.  
  8.  
  9. #define SMALLRES 15
  10. #define BIGRES   39
  11.  
  12. extern char *optarg;
  13.  
  14. main(argc, argv)
  15.     int    argc;
  16.     char **argv;
  17. {
  18.     Object  *torus;
  19.     Object  *torus_pair;
  20.     Object  *chain;
  21.     FILE    *fp ;
  22.     Surf_desc surf;
  23.  
  24.     char    *imfile_name;
  25.     int      mode;
  26.     int      c;
  27.     int      size;
  28.  
  29.     imfile_name = "chain.ppm";
  30.     mode = PHONG;
  31.     size = 256;
  32.  
  33.     while ((c = getopt(argc, argv, "pgfls:")) != EOF) {
  34.         switch (c) {
  35.           case 'p':
  36.             mode = PHONG;
  37.             imfile_name = "chain.ppm";
  38.             break;
  39.  
  40.           case 'g':
  41.             mode = GOURAUD;
  42.             imfile_name = "chain.ppm";
  43.             break;
  44.  
  45.           case 'f':
  46.             mode = FLAT;
  47.             imfile_name = "chain.ppm";
  48.             break;
  49.  
  50.           case 'l':
  51.             mode = LINE;
  52.             imfile_name = "chain.pbm";
  53.             break;
  54.  
  55.           case 's':
  56.             size = atoi(optarg);
  57.             break;
  58.         }
  59.     }
  60.  
  61.     sipp_init();
  62.  
  63.     lightsource_create(1.0, 1.0, 1.0, 0.9, 0.9, 0.9, LIGHT_DIRECTION);
  64.     lightsource_create(-1.0, -1.0, 0.5, 0.4, 0.4, 0.4, LIGHT_DIRECTION);
  65.  
  66.     surf.ambient = 0.5;
  67.     surf.specular = 0.6;
  68.     surf.c3 = 0.2;
  69.     surf.color.red = 0.8;
  70.     surf.color.grn = 0.6;
  71.     surf.color.blu = 0.3;
  72.     surf.opacity.red = 1.0;
  73.     surf.opacity.grn = 1.0;
  74.     surf.opacity.blu = 1.0;
  75.     
  76.     torus = sipp_torus(1.0, 0.23, BIGRES, SMALLRES, &surf, basic_shader, 
  77.                        WORLD);
  78.     torus_pair = object_create();
  79.     object_add_subobj(torus_pair, torus);
  80.     torus = object_instance(torus);
  81.     object_move(torus, 0.0, -1.375, 0.0);
  82.     object_rot_y(torus, M_PI / 2.0);
  83.     object_add_subobj(torus_pair, torus);
  84.     
  85.     chain = object_create();
  86.     object_move(torus_pair, -1.375, 1.375, 0.0);
  87.     object_add_subobj(chain, torus_pair);
  88.     torus_pair = object_instance(torus_pair);
  89.     object_rot_z(torus_pair, M_PI / 2.0);
  90.     object_move(torus_pair, -1.375, -1.375, 0.0);
  91.     object_add_subobj(chain, torus_pair);
  92.     torus_pair = object_instance(torus_pair);
  93.     object_rot_z(torus_pair, M_PI);
  94.     object_move(torus_pair, 1.375, -1.375, 0.0);
  95.     object_add_subobj(chain, torus_pair);
  96.     torus_pair = object_instance(torus_pair);
  97.     object_rot_z(torus_pair, 3.0 * M_PI / 2.0);
  98.     object_move(torus_pair, 1.375, 1.375, 0.0);
  99.     object_add_subobj(chain, torus_pair);
  100.     
  101.     object_add_subobj(sipp_world, chain);
  102.  
  103.     camera_params(sipp_camera, 5.0, -2.0, 15.0,  0.5, 0.0, 0.0, 
  104.                   0.0, 0.0, 1.0,  0.25);
  105.  
  106.     printf("Rendering, wait...");
  107.     fflush(stdout);
  108.  
  109.     fp = fopen(imfile_name, "w");
  110.     render_image_file(size, size, fp, mode, 2);
  111.     printf("Done.\n");
  112.  
  113.     exit(0);
  114. }
  115.